
class PID(object):
    """A simple PID controller."""

    Gkp = 0
    Gki = 0
    Gkd = 0


    def __init__(
        _,
        kp = 1.0,
        ki = 0.0,
        kd = 0.0
    ):
        _.e0 = 0
        _.integral = 0

        _.Kp , _.Ki , _.Kd  = kp , ki , kd


    def coeficientes (_,kp,ki,kd):
        _.Kp = kp
        _.Ki = ki
        _.Kd = kd


    def calcule (_, e1) :

        ctrl = (e1          * _.Kp) +  \
               (_.integral  * _.Ki) +  \
               ((e1 - _.e0) * _.Kd) 

        _.integral = _.integral + 0.5 * (_.e0 + e1)

        _.e0 = e1

        return ctrl

